<?php

	include("common.php");
	
	if(!empty($_POST)){
		mysql_query("UPDATE `197_sidebar` SET `title` = '" . $_POST['title'] . "', `content` = '" . $_POST['content'] . "', `position` = " . $_POST['position'] . " WHERE `sidebar_id` = " . $_POST['sidebar_id']);
		include("header.php");
?>
<?php if(!AJAX){ ?><h1>修改側欄項目</h1><?php } ?>
<p>修改成功<?php if(!AJAX){ ?>，請<a href="sidebarFind.php">按此</a>返回<?php } ?>。</p>
<?php

		include("sidebar.php");
		include("footer.php");
		
		exit;
	
	}
	
	$result = mysql_query("SELECT * FROM `197_sidebar` WHERE `sidebar_id` = " . $_GET['sidebar_id']);
	$row = mysql_fetch_assoc($result);
	
?>
<?php include("header.php"); ?>
<h1>編輯側欄項目</h1>
<div id="edit-result-dialog">
</div>
<script type="text/javascript" defer="defer">
	$("#edit-result-dialog").dialog({
		width: 300,
		height: 210,
		autoOpen: false,
		title: "修改側欄項目",
		modal: true,
		draggable: false,
		resizable: false
	});
	function editSidebar(){
		$("#edit-result-dialog").dialog("option", "buttons", { "關閉": function(){ location.replace("sidebarFind.php"); } });
		$("#edit-result-dialog").html("<img src='../images/ajax-loader.gif' />");
		$("#edit-result-dialog").dialog("open");
		$.post("sidebarEdit.php?ajax=true", { content: $("#content").val(), "title": $("#title").val(), sidebar_id: $("#sidebar_id").val(), position: $("#position").val() }, function(r){ $("#edit-result-dialog").html(r) });
	}
</script>
<form action="sidebarEdit.php" onsubmit="editSidebar(); return false;" method="POST">
	<p><label>標題：<input type="text" name="title" id="title" value="<?php echo $row['title']; ?>" /></label></p>
	<textarea name="content" cols="50" rows="20" id="content"><?php echo $row['content']; ?></textarea>
	<p><label>位置：<select name="position" id="position"><option value="0"<?php if($row['position'] == 0){ ?> selected="selected"<?php } ?>>左</option><option value="1"<?php if($row['position'] == 1){ ?> selected="selected"<?php } ?>>右</option></select></label></p>
	<p><input type="submit" value="編輯" />｜<a href="sidebarFind.php">返回</a></p><input id="sidebar_id" type="hidden" name="sidebar_id" value="<?php echo $_GET['sidebar_id']; ?>" />
</form>
<?php include("sidebar.php"); ?>
<?php include("footer.php"); ?>